home *** CD-ROM | disk | FTP | other *** search
- //---------------------------------------------------------------------------
- #include <vcl\vcl.h>
- #pragma hdrstop
-
- #include "Raten3.h"
- //---------------------------------------------------------------------------
- #pragma resource "*.dfm"
-
- const int Max = 12; // ein Dutzend ist genug
- TForm1 *Form1;
- int Eingabe, Zufall, Versuche, Knopf;
-
- //---------------------------------------------------------------------------
- __fastcall TForm1::TForm1(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button1Click(TObject *Sender)
- {
- Edit1->SetFocus ();
- Eingabe = StrToInt (Edit1->Text);
-
- // Versuche mitzΣhlen und bei Max warnen
- Versuche++;
- if (Versuche <= Max)
- Label2->Caption = IntToStr (Versuche) + ". Versuch:";
- else
- Label2->Caption = "Es reicht!";
-
- // Eingabe auswerten ob zu klein oder zu gro▀
- if (Eingabe < Zufall) Label1->Caption = "Deine Zahl ist zu klein!";
- if (Eingabe > Zufall) Label1->Caption = "Deine Zahl ist zu gro▀!";
-
- // Wenn richtig geraten, neues Spiel anbieten
- if (Eingabe == Zufall)
- {
- Label1->Caption = "Richtig geraten!";
- Knopf = Application->MessageBox ("", "Neues Spiel?", 4+32);
-
- // Wenn neues Spiel gewⁿnscht, Startwerte/Zufallszahl neu
- if (Knopf == IDYES)
- {
- Label1->Caption = "Ich denke mir eine neue Zahl!";
- Label2->Caption = "Rate mal!";
- Zufall = random (1000) + 1;
- Versuche = 1;
- }
-
- // Wenn kein neues Spiel, Programmende
- else
- Close ();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::FormCreate(TObject *Sender)
- {
- randomize ();
- Zufall = random (1000) + 1;
- Versuche = 1;
- }
- //---------------------------------------------------------------------------